<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Config;

/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {
        // 粉丝总量
        $userCount = db('members')->where('wechat_id',$this->wechat_id)->count();

        // 新增粉丝，3天内新增的粉丝数量
        $day = date('Y-m-d',time());
        $map['subscribe_time'] = array('gt',strtotime($day)-86400*3);
        $userNewCount = db('members')->where('wechat_id',$this->wechat_id)->where($map)->count();

        // 昨日新增用户
        $yetoday = strtotime('-1 day');
        $map['subscribe_time'] = array('BETWEEN',[$yetoday,$yetoday+86399]);
        $yetodayCount = db('members')->where('wechat_id',$this->wechat_id)->where($map)->count();

        // 总的消息数量
        $messageCount = db('message_logs')->where('wechat_id',$this->wechat_id)->count();
        $this->assign('messageCount',number_format($messageCount,2));
        $this->assign('userCount',number_format($userCount,2));
        $this->assign('userNewCount',number_format($userNewCount,2));
        $this->assign('yetodayCount',number_format($yetodayCount,2));
        return $this->view->fetch();
    }

}
